﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Toenda.Foundation.Globalization {
	/// <summary>
	/// Provides informatione about a holiday.
	/// </summary>
	public class NationalHoliday : IComparable, ICloneable {
		private DateTime _date;
		private string _name;
		private bool _isStatic;

		/// <summary>
		/// Initializes a new instance of the <see cref="NationalHoliday"/> class.
		/// </summary>
		/// <param name="date">The date.</param>
		/// <param name="name">The name.</param>
		/// <param name="isStatic">if set to <c>true</c> [is static].</param>
		public NationalHoliday(DateTime date, string name, bool isStatic) {
			this._date = date;
			this._isStatic = isStatic;

			this._name = name == null 
				? string.Empty 
				: name;
		}

		/// <summary>
		/// Gets or sets the date.
		/// </summary>
		/// <value>The date.</value>
		public DateTime Date {
			get { return _date; }
			set { _date = value; }
		}

		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>The name.</value>
		public string Name {
			get { return _name; }
			set { _name = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether the holiday is static.
		/// </summary>
		/// <value><c>true</c> if the holiday is static; otherwise, <c>false</c>.</value>
		public bool IsStatic {
			get { return _isStatic; }
			set { _isStatic = value; }
		}

		/// <summary>
		/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
		/// </summary>
		/// <param name="obj">An object to compare with this instance.</param>
		/// <returns>
		/// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
		/// Value
		/// Meaning
		/// Less than zero
		/// This instance is less than <paramref name="obj"/>.
		/// Zero
		/// This instance is equal to <paramref name="obj"/>.
		/// Greater than zero
		/// This instance is greater than <paramref name="obj"/>.
		/// </returns>
		/// <exception cref="T:System.ArgumentException">
		/// 	<paramref name="obj"/> is not the same type as this instance.
		/// </exception>
		public int CompareTo(object obj) {
			if(obj.GetType() != this.GetType()) {
				throw new ArgumentException();
			}

			NationalHoliday Tmp = (NationalHoliday)obj;

			if(this.Date > Tmp.Date) {
				return 1;
			}
			else if(this.Date < Tmp.Date) {
				return -1;
			}
			else {
				return 0;
			}
		}

		/// <summary>
		/// Creates a new object that is a copy of the current instance.
		/// </summary>
		/// <returns>
		/// A new object that is a copy of this instance.
		/// </returns>
		public object Clone() {
			return new NationalHoliday(this._date, this._name, this._isStatic);
		}
	}
}
